<?php

namespace addons\HuaFeng\backend\controllers;

use Yii;
use addons\HuaFeng\common\models\Store;
use common\traits\Curd;
use common\models\base\SearchModel;
use yii\web\Controller;

/**
* Store
*
* Class StoreController
* @package addons\HuaFeng\backend\controllers
*/
class StoreController extends BaseController
{
    use Curd;

    /**
    * @var Store
    */
    public $modelClass = Store::class;

    /**
    * 首页
    *
    * @return string
    * @throws \yii\web\NotFoundHttpException
    */
    public function actionIndex()
    {
        $searchModel = new SearchModel([
            'model' => $this->modelClass,
            'scenario' => 'default',
            'partialMatchAttributes' => [], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC
            ],
            'pageSize' => $this->pageSize
        ]);
        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);

        return $this->render('index', [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
        ]);
    }

    /**
     * 编辑/创建
     *
     * @return mixed
     */
//    public function actionEdit()
//    {
//Yii::$app->user->id
//        $id = Yii::$app->request->get('id', null);
//        $model = $this->findModel($id);
//        $post = Yii::$app->request->post();
//        $post['user_id'] = 1;
//        if ($model->load($post) && $model->save()) {
//            return $this->referrer();
//        }
//
//        return $this->render($this->action->id, [
//            'model' => $model,
//        ]);
//    }
}
